package info.mhylle.mediaplayer.playlist;

import helliker.id3.MP3File;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MusicAlbum {

    private String artist;
    private String name;

    private String webFriendlyArtistName;
    private String webFriendlyAlbumName;

    List<MP3File> tracks;
    private File coverartpath;
    private int releaseYear;


    public MusicAlbum() {
        tracks = new ArrayList<MP3File>();
    }

    public String getArtist() {
        return artist;
    }

    public void setArtist(String artist) {
        this.artist = artist;
        setWebFriendlyArtistName(removeWebUnfriendlyChars(artist));
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
        setWebFriendlyAlbumName(removeWebUnfriendlyChars(name));
    }

    public void addTrack(MP3File mp3) {
        tracks.add(mp3);
    }

    public List<MP3File> getTracks() {
        return tracks;
    }

    public void addCoverArt(File coverartpath) {
        this.coverartpath = coverartpath;
    }

    public File getCoverartpath() {
        return coverartpath;
    }

    public void setReleaseYear(int releaseYear) {
        this.releaseYear = releaseYear;
    }

    public int getReleaseYear() {
        return releaseYear;
    }

    public String getWebFriendlyArtistName() {
        return webFriendlyArtistName;
    }

    public void setWebFriendlyArtistName(String webFriendlyArtistName) {
        this.webFriendlyArtistName = webFriendlyArtistName;
    }

    public String getWebFriendlyAlbumName() {
        return webFriendlyAlbumName;
    }

    public void setWebFriendlyAlbumName(String webFriendlyAlbumName) {
        this.webFriendlyAlbumName = webFriendlyAlbumName;
    }

    private String removeWebUnfriendlyChars(String s) {
        String s1 = s.replaceAll(" ", "");
        String s2 = s1.replaceAll(",", "");
        String s3 = "";
        String s4 = "";
        while (s2.indexOf(".") > 0) {
            int lastIndex = s2.indexOf(".");
            s3 += s2.substring(0, lastIndex);
            s2 = s2.substring(lastIndex + 1, s2.length());
        }
        s3 += s2;
        while (s3.indexOf("[") > 0) {
            int lastIndex = s3.indexOf("[");
            s4 += s3.substring(0, lastIndex);
            s3 = s3.substring(lastIndex + 1, s3.length());
        }
        s4 += s3;
//        String s4 = s3.replaceAll("[", "");
        String s5 = s4.replaceAll("]", "");
        return s5;

    }
}
